  

    function Encrypt(word,k){  
         var key = CryptoJS.enc.Utf8.parse(k);   
  
         var srcs = CryptoJS.enc.Utf8.parse(word);  
         var encrypted = CryptoJS.AES.encrypt(srcs, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});  
         return encrypted.toString();  
    }  
    function Decrypt(word,k){  
         var key = CryptoJS.enc.Utf8.parse(k);   
  
         var decrypt = CryptoJS.AES.decrypt(word, key, {mode:CryptoJS.mode.ECB,padding: CryptoJS.pad.Pkcs7});  
         return CryptoJS.enc.Utf8.stringify(decrypt).toString();  
    }  
    
    function enStr(a){
        var aeskey = api.loadSecureValue({
            sync: true,
            key: 'aeskey'
        });
        aeskey = a+aeskey;
        var sign = hex_md5(aeskey);
        var p = {"sign":sign,"content":a};
        var str = JSON.stringify(p);
        var para = Encrypt(str,aeskey);
        return para;
    }
    
    //加密请求
    function encApiAjax(l,u,callback){ 
      var aeskey = api.loadSecureValue({
		   sync: true,
		   key: 'aeskey'
	  });
	  var salt = api.loadSecureValue({
	       sync: true,
	       key: 'salt'
	  });
	  var sign = md5(l+salt);//sha256(l);
	  var pa = {'sign':sign,'content':l};
	  var para = Encrypt(JSON.stringify(pa),aeskey);
      api.ajax({
	        url: u,
	        timeout: 15,
	        method: 'post',
	        data:{ 
		            values: {
			            para: para
			        }
		        }
        },function(ret,err){
            callback(ret,err);   
        });
    }
    
    //普通请求
    function apiAjax(l,u,callback){
        var para = eval("("+l+")");
        api.ajax({
	        url: u,
	        timeout: 15,
	        encode: true,
	        charset: 'utf-8',
	        method: 'post',
	        data:{ 
		            values: para
		        }
        },function(ret,err){
            //console.log(JSON.stringify(ret));
            callback(ret,err);  
        });
    }
    
    function signAjax(l,u,callback){
        var para = eval("("+l+")");
        para = objKeySort(para);
        var signature = md5(JSON.stringify(para)+"dyxzbzyq");
	    para["signature"] = signature;
	    console.log(JSON.stringify(para));
        api.ajax({
	        url: u,
	        timeout: 15,
	        encode: true,
	        charset: 'utf-8',
	        method: 'post',
	        data:{ 
		            values: para
		        }
        },function(ret,err){
            //console.log(JSON.stringify(ret));
            callback(ret,err);  
        });
    }
    
    //文件上传
    function fileAjax(m,u,callback){
       var file = {};
       if(m.length>0){
          file = eval("("+m+")");
       }
        api.ajax({
	        url: u,
	        timeout: 15,
	        encode: true,
	        charset: 'utf-8',
	        method: 'post',
	        data:{
		            files : file
		        }
        },function(ret,err){
            //console.log(JSON.stringify(ret));
            callback(ret,err);  
        });
    }
    
    
    //排序的函数
    function objKeySort(arys) { 
        //先用Object内置类的keys方法获取要排序对象的属性名，再利用Array原型上的sort方法对获取的属性名进行排序，newkey是一个数组
        var newkey = Object.keys(arys).sort();　　 
        //console.log('newkey='+newkey);
        var newObj = {}; //创建一个新的对象，用于存放排好序的键值对
        for(var i = 0; i < newkey.length; i++) {
            //遍历newkey数组
            newObj[newkey[i]] = arys[newkey[i]]; 
            //向新创建的对象中按照排好的顺序依次增加键值对

        }
        return newObj; //返回排好序的新对象
    }
